<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top: 10px;
  }
  .task-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
  .img{
   width: 150px;
   height: 100px;
   float: left;
   margin: 5px;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>待转化客户</span>
    </div>
    <div class="line"></div>
    <customer-form
      class="customer-form"
      @on-success-valid="handleSubmit"
      :title="title" :statearr="statearr">
    </customer-form>
    <!-- <Button
      icon="md-add"
      type="primary"
      @click="handleClick">
      添加任务
    </Button> -->
    <customer-drawer
      @customer-valid="handleEdit"
      :row="row"
      :detailTitle="title">
    </customer-drawer>
    <task-list-confirm-modal
      :confirmData="confirmData"
      @confirm-task-list-valid="handleConfirm">
    </task-list-confirm-modal>
    <customer-table
      class="table"
      :tableData="historyData"
      :page="page"
      :pageSize="pageSize"
      @handle-detail="handleClick"
      @handle-click="handleClick"
      :title="title"
      :list="lossList"
      :btnTitle="'详情'"
      :loading="loading"
      >
    </customer-table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      @change-page-size="changePageSize"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import CustomerTable from '_c/customer-table'
import CustomerForm from '_c/customer-form'
import CustomerDrawer from '_c/customer-drawer'
import TaskListConfirmModal from '_c/task-list-confirm-modal'
import TablePage from '_c/table-page'
export default {
  components: {
    CustomerTable,
    CustomerForm,
    CustomerDrawer,
    TaskListConfirmModal,
    TablePage
  },
  data () {
    return {
      page: 1,
      title: '客户管理流失客户',
      confirmData: {},
      postData: {},
      playload: null,
      loading: true,
      statearr: '0,1,2,3,4,5'
    }
  },
  computed: {
    ...mapState({
      lossList: state => state.loss.lossList,
      dataCount: state => state.loss.lossDataCount,
      historyData: state => state.loss.lossHistoryData,
      pageSize: state => state.loss.lossPageSize,
      row: state => state.loss.row
    })
  },
  methods: {
    ...mapActions([
      'getLossList',
      'getNameList',
      'getLossCurrentRow',
      'editLossData',
      'updateCustomerDrawerState',
      'updateConfirmModalState',
      'changeLossPage',
      'changeLossPageSize'
    ]),
    handleSubmit (playload) {
      // console.log(playload)
      this.loading = true
      this.postData = {
        ctime: playload.ctime,
        uname: playload.uname,
        tel: playload.tel,
        muid: playload.muid,
        // appointime: playload.appointime,
        state: playload.state,
        state0: 1,
        statearr: playload.statearr
      }
      this.getLossList({
        ...this.postData,
        rows: this.rows
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    handleClick (row) {
      // console.log(row)
      let newRow = {}
      this.id = row.id
      if (row) {
        newRow = Object.assign({}, row)
      }
      this.getLossCurrentRow(newRow)
      this.updateCustomerDrawerState(true)
    },
    handleEdit (playload, id) {
      // console.log(playload)
      this.confirmData = playload
      this.updateCustomerDrawerState(false)
      this.updateConfirmModalState(true)
    },
    handleConfirm () {
      this.loading = true
      this.editLossData(this.confirmData).then(
        this.getLossList({
          state0: 1,
          page: this.page,
          rows: this.rows,
          ...this.postData
        }).then((res) => {
          if (res.data.state === '000') {
            this.loading = false
          }
        })
      )
      this.updateConfirmModalState(false)
    },
    changePage (index) {
      this.loading = true
      this.page = index
      this.changeLossPage(index)
      this.getLossList({
        state0: 1,
        page: index,
        rows: this.rows,
        ...this.postData
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePageSize (value) {
      this.loading = true
      this.rows = value
      this.changeLossPageSize(value)
      this.changePage(this.page)
      this.getLossList({
        state0: 1,
        rows: value,
        ...this.postData
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    }
  },
  created () {
    this.getLossList({
      state0: 1,
      statearr: '0,1,2,3,4,5'
    }).then((res) => {
      if (res.data.state === '000') {
        this.loading = false
      }
    })
    this.getNameList({})
  }
}
</script>
